<template>
  <section>
    <van-sticky>
      <PageHeader title="平台收支管理"/>
    </van-sticky>

    <van-list
      class="mt10"
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="requestData">
      <div class="flex flex-col pd10 bg-color-white mt10 ml10 mr10 round-box font-common" v-for="(item, index) in dataList" :key="index">
        <div class="flex flex-row flex-center pb10">
          <div class="flex flex-row flex-left flex-1">
            <span v-if="item.type == PLATFORM_ACCOUNT_BOOK_TYPE_INCOME">收入：</span>
            <span v-if="item.type == PLATFORM_ACCOUNT_BOOK_TYPE_EXPEND">支出：</span>
            {{item.money}}元
          </div>

          <div class="flex flex-row flex-right flex-1">
            {{item.dateline|timeFormat('yyyy-MM-dd hh:mm:ss')}}
          </div>
        </div>

        <div class="flex flex-row flex-left pt10 border-top-gray">
          备注：{{item.remark}}
        </div>
      </div>
    </van-list>

  </section>
</template>

<script>
import PageHeader from "../componets/PageHeader";
import {platformAccountBookListsUri} from "../../common/api";
import {PLATFORM_ACCOUNT_BOOK_TYPE_EXPEND, PLATFORM_ACCOUNT_BOOK_TYPE_INCOME} from "../../common/constants";

export default {
  components: {
    PageHeader
  },
  data() {
    return {
      PLATFORM_ACCOUNT_BOOK_TYPE_INCOME: PLATFORM_ACCOUNT_BOOK_TYPE_INCOME,
      PLATFORM_ACCOUNT_BOOK_TYPE_EXPEND: PLATFORM_ACCOUNT_BOOK_TYPE_EXPEND,

      currentPage: 1,
      lastPage: 0,
      total: 0,
      pageSize: 10,
      loading: false,
      finished: false,
      dataList: []
    }
  },
  methods: {
    requestData() {
      const that = this;
      this.loading = true;
      const url = platformAccountBookListsUri + '?page_size=' + that.pageSize + '&page=' + that.currentPage;
      this.$http.get(url).then(response => {
        let {code, msg, data} = response.body
        if (code != 0) {
          that.toast(msg);
        } else {
          that.loading = false;
          if (that.currentPage >= data.last_page) {
            that.finished = true;
          }
          that.currentPage = that.currentPage + 1;
          for (let i = 0; i < data.data.length; i++) {
            that.dataList.push(data.data[i]);
          }
          that.total = data.total;
          that.lastPage = data.last_page;
        }
      }, response => {
        // error callback
      })
    }
  },
  mounted: function () {

  }
}
</script>

<style scoped>

</style>
